/**
 * 判断莫条数据是否在列表中
 * @param key 查询数值
 * @param list 数据列表非对象类型
 * @returns {boolean}
 */
export const keyInList = (key, list = []) => (list.some(item => (item === key)));
/**
 * 判断莫条数据是否在列表中
 * @param data  克隆对象数据源
 * @returns object   部分原生JavaScript内置对象无法实现克隆
 */
export const deepCopy = (data) => {
    return JSON.parse(JSON.stringify(data))
};
/**
 * 获取当前时间或根据时间对象获取时间信息
 * @param newData 任意时间对象
 * @returns {{timeStamp: number, hours: number, seconds: number, mouth: number, week: number, year: number, minutes: number, millisecond: number, day: number, weekZh: string}}
 * @constructor
 */
export const getTimeInfo = (newData) => {
    const date = newData || new Date();
    const timeStamp = date.getTime();
    const year = date.getFullYear();
    const mouth = (date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : '0' + (date.getMonth() + 1);
    const week = date.getDay();
    const hours = date.getHours() + '';
    const minutes = date.getMinutes() + '';
    const seconds = date.getSeconds() + '';
    const day = (date.getDate() >= 10 ? date.getDate() : '0' + date.getDate()) + '';
    const millisecond = date.getMilliseconds() + '';
    return {
        timeStamp,
        year,
        mouth,
        day,
        hours,
        minutes,
        seconds,
        millisecond,
        week,
        weekZh: ['日', '一', '二', '三', '四', '五', '六'][week - 1]
    }
};
/**
 * 获取当前时间信息
 * @param linkStr 年月日链接字符
 * @param NewDate 时间对象
 */
export const formatTime = (NewDate, linkStr = '-') => {
    const isString = typeof NewDate === 'string';
    const {
        timeStamp,
        year,
        mouth,
        week,
        day,
        hours,
        minutes,
        seconds
    } = getTimeInfo(isString ? new Date(NewDate) : NewDate);
    // 链接字符
    const link = linkStr || '-';
    // 显示年月日
    const YYYYMMDD = [year, (mouth + '').padStart(2, '0'), (day + '').padStart(2, '0')].join(link);
    const HHmm = [('' + hours).padStart(2, '0'), minutes.padStart(2, '0')].join(':');
    const HHmmss = [HHmm, seconds.padStart(2, '0')].join(':');
    return {
        YYYYMM: [year, (mouth + '').padStart(2, '0')].join(link),
        timeStamp,
        weekZh: '星期' + ['日', '一', '二', '三', '四', '五', '六'][week - 1],
        YYYYMMDD,
        YYYYMMDDHHMM: YYYYMMDD + HHmm,
        YYYYMMDDHHMMSS: (YYYYMMDD + ' ') + HHmmss
    }
};
/**
 * 金钱输入框
 * @param orgNum 输入数据
 * @param num 精度
 */
export const showMoney = (orgNum, num = 2) => {
    if (!orgNum) {
        return '';
    }
    return (parseFloat(orgNum + '').toFixed(num)+'').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,')
};
